import JSEncrypt from 'jsencrypt';

// 密钥对生成 http://web.chacuo.net/netrsakeypair

const publicKey =
    'MFwwDQYJKoZIhvcNAQEBBQADSwAwSAJBALrSL0td/IrdiJvroFgK0fUuvxcrMmS3RCiPgmEMmfbIvQdPGBYI68P9LKJZiOjEwXXva7zyiWyCEj5E41lWd78CAwEAAQ==';

const privateKey =
    'MIIBVQIBADANBgkqhkiG9w0BAQEFAASCAT8wggE7AgEAAkEAutIvS138it2Im+ugWArR9S6/FysyZLdEKI+CYQyZ9si9B08YFgjrw/0solmI6MTBde9rvPKJbIISPkTjWVZ3vwIDAQABAkEAqwDBMadyBloJNU9UkcI1tMt5Nmff1Li7trTFjrfOJki83uZaIfxJDfR1KblZ61/zvmtFhd331uQULT5N1JpyQQIhAPfZFi1oOFwydPyLDi3s2LC/fFjypmjEwuj5TP889c75AiEAwPc+L9zQvFERo9EbyFlWtLHhAUV+i5h8hgomvD1j0ncCIQCI4OlwllhaAru9JYblMiLSKk6gSRJCVjhWtigh5ibS8QIgBv1tzUIMdaXiI7MBdKJ315fR9L/Vs6zUZe6cNJlsskUCIDhHUF2CyvLcVxmo5HmjSpBOOIyNK9Vnpt6it55k6en8';

// 加密
export function encrypt(txt: string) {
    const encryptor = new JSEncrypt();
    encryptor.setPublicKey(publicKey); // 设置公钥
    return encryptor.encrypt(txt); // 对数据进行加密
}

// 解密
export function decrypt(txt: string) {
    const encryptor = new JSEncrypt();
    encryptor.setPrivateKey(privateKey); // 设置私钥
    return encryptor.decrypt(txt); // 对数据进行解密
}
